﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Orchard;
using Orchard.Mvc.Filters;

namespace PJS.Bootstrap.Filters
{
    public class LayoutFilter : FilterProvider, IResultFilter
    {
        private readonly IWorkContextAccessor _wca;

        public LayoutFilter(IWorkContextAccessor wca)
        {
            _wca = wca;
        }

        public void OnResultExecuting(ResultExecutingContext filterContext)
        {
            
            var workContext = _wca.GetContext();
            
            if (filterContext.RequestContext.HttpContext.Request.IsAjaxRequest()) {
                workContext.Layout.Metadata.Alternates.Add("Layout_Null");
            }
        }

        public void OnResultExecuted(ResultExecutedContext filterContext)
        {
        }
    }
}